<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        td {
            padding: 2px 0px;
            text-align: left;
            border: 1px solid #999;
        }
    </style>
    <link href="/resources/css/table.css?r=3" rel="stylesheet">
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js?v=123"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <link  href="/resources/viewer/viewer.css" rel="stylesheet">
    <script src="/resources/viewer/viewer.js"></script>
</head>
<body>

<div>
<table style="width:100%;">

    <tr>
        <td colspan="9">
            <button onclick="back()" class="btn btn-primary" type="button" style="float:right;margin-right:20px;">返回</button>
        </td>


    </tr>

<tr>
    <td class="name">
        监控设备：
    </td>
    <td>
        <select name="deviceId" id="deviceId"  class="form-control form-data" readonly>
        </select>
        <input type="hidden" name="id" class="form-data" readonly>
    </td>
    <td class="name" title="生产（经营）企业所在县、市、区">
        地址：
    </td>
    <td>
        <input type="text" name="companyAdd" id="companyAdd"  readonly
               class="form-control form-data ">
    </td>
    <td class="name" title="流向地（县、市、区）">
        流向地：
    </td>
    <td>
        <input type="text" name="lxd" id="lxd"      readonly
               class="form-control form-data ">
    </td>
    <td class="name">
        用途：
    </td>
    <td>
        <input type="text" name="use" id="use"  readonly
               class="form-control form-data ">
    </td>
</tr>
<tr>
    <td class="name" >
        购买单位<span style="cursor: pointer" onclick="showBuyCompany()">（查看）</span>  ：
    </td>
    <td>
        <select name="buyCompanyId" id="buyCompanyId" class="form-control form-data" readonly>
        </select>
    </td>
    <td class="name">
        运输公司<span style="cursor: pointer" onclick="showTransCompany()">（查看）</span>：
    </td>
    <td>
        <select name="transportCompanyId" id="transportCompanyId" class="form-control form-data" readonly>
        </select>
    </td>
    <td class="name">
        运输车辆牌号：
    </td>
    <td>
        <input type="text" name="transportCarInfo"  readonly
               class="form-control form-data ">
    </td>
    <td class="name">
        联系方式：
    </td>
    <td>
        <input type="text" id="buyCompanyTelephone" name="buyCompanyTelephone" readonly
               class="form-control form-data ">
    </td>
</tr>
<tr>
    <td class="name" >
        购买单位经办人：
    </td>
    <td>
        <input type="text" name="buyerName" id="buyerName" readonly
               class="form-control form-data ">
    </td>
    <td class="name">
        性别：
    </td>
    <td>
        <select name="buyerSex" id="buyerSex" class="form-control form-data"  readonly
                style="width:150px;float: left" >
            <option value="man">男</option>
            <option value="woman">女</option>
        </select>
    </td>
    <td class="name">
        身份证号：
    </td>
    <td>
        <input type="text" id="buyerCard" name="buyerCard"  readonly
               class="form-control form-data ">
    </td>
    <td class="name">
        联系方式：
    </td>
    <td>
        <input type="text" id="buyerTelephone" name="buyerTelephone"readonly
               class="form-control form-data ">
    </td>
</tr>
<tr>
    <td class="name">
        驾驶员姓名：
    </td>
    <td>
        <input type="text" name="name" readonly
               class="form-control driver ">
    </td>
    <td class="name">
        性别：
    </td>
    <td>
        <select name="sex"  class="form-control driver" readonly
                style="width:150px;float: left" >
            <option value="man">男</option>
            <option value="woman">女</option>
        </select>
    </td>
    <td class="name">
        身份证号：
    </td>
    <td>
        <input type="text"  name="idCard"  readonly
               class="form-control driver ">
    </td>
    <td class="name">
        联系方式：
    </td>
    <td>
        <input type="text"  name="telephone"  readonly
               class="form-control driver ">
    </td>
</tr>
<tr>
    <td class="name">
        押运员姓名：
    </td>
    <td>
        <input type="text" name="name" readonly
               class="form-control supercargo ">
    </td>
    <td class="name">
        性别：
    </td>
    <td>
        <select name="sex"   style="width:150px;float: left" readonly
                class="form-control supercargo">
            <option value="man">男</option>
            <option value="woman">女</option>
        </select>
    </td>
    <td class="name">
        身份证号：
    </td>
    <td>
        <input type="text" id="idCard" name="idCard" readonly
               class="form-control supercargo ">
    </td>
    <td class="name">
        联系方式：
    </td>
    <td>
        <input type="text"  name="telephone" readonly
               class="form-control supercargo ">
    </td>
</tr>
<tr>
    <td class="name" >
        开始时间：
    </td>
    <td>
        <input type="text" name="timeBegin" id="timeBegin"     readonly
               class="form-control form-data "  onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
    </td>
    <td class="name">
        结束时间：
    </td>
    <td>
        <input type="text" name="timeEnd" id="timeEnd"      readonly
               class="form-control form-data "  onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
    </td>
    <td class="name">
        数量：
    </td>
    <td >
        <!--  <input type="text" id="amount" name="amount"
                 class="form-control form-data" style="width:80% !important;">
          <input type="text"  name="unit" readonly
                 class="form-control form-data col-md-7 col-xs-12" style="width:20% !important;">-->
        <input type="text" id="amount" name="amount"        readonly
               class="form-control form-data col-md-7 col-xs-12" style="width:50% !important;">
        <input type="text"  name="unit" readonly
               class="form-control form-data col-md-7 col-xs-12" style="width:50% !important;">
    </td>
    <td class="name">
        采集值：
    </td>
    <td >
        <!--  <input type="text" id="amount" name="amount"
                 class="form-control form-data" style="width:80% !important;">
          <input type="text"  name="unit" readonly
                 class="form-control form-data col-md-7 col-xs-12" style="width:20% !important;">-->
        <input type="text" id="monitorValueLora" name="monitorValueLora"   readonly
               class="form-control form-data col-md-7 col-xs-12" style="width:100% !important;">
    </td>
</tr>

<tr>
    <td class="name">
        描述：
    </td>
    <td colspan="7">
        <textarea class="form-control form-data" name="desc" rows="3" placeholder="" readonly></textarea>
    </td>
</tr>
<tr>
    <td class="name">
        公司备注：
    </td>
    <td colspan="7">
        <textarea class="form-control form-data" name="companyRemark" rows="3" placeholder="" readonly></textarea>
    </td>
</tr>
<tr>
    <td class="name">
        状态：
    </td>
    <td colspan="3">
        <div class="col-md-6 col-sm-6 col-xs-12">
        <input style="width:15px;height:15px" type="radio" name="process" class="form-data" value="auditFail"  onclick="$('.pass').hide()"/>
        <span>审核失败</span>
        <input style="width:15px;height:15px" type="radio" name="process" class="form-data" value="auditSuccess" onclick="$('.pass').show()"/>
        <span>审核通过</span>
        <input  type="hidden" name="refuseFlag" class="form-data" />
        </div>
    </td>
    <td class="name pass" >
        通过方式：
    </td>
    <td  class="pass" colspan="3">
        <div class="col-md-6 col-sm-6 col-xs-12">
        <input style="width:15px;height:15px" type="radio" name="passWay" class="form-data" value="same" onclick="$('#auditRemark').val('数据统一')"/>
        <span>数据统一</span>
        <input style="width:15px;height:15px" type="radio" name="passWay" class="form-data" value="hedging" onclick="$('#auditRemark').val('对冲')"/>
        <span>对冲</span>
        <input style="width:15px;height:15px" type="radio" name="passWay" class="form-data" value="other" onclick="$('#auditRemark').val('其他')"/>
        <span>其他</span>
        </div>
    </td>
</tr>
<tr>
    <td class="name" >
        审核说明：
    </td>
    <td colspan="7">
        <textarea class="form-control form-data" name="auditRemark" rows="3" placeholder="" id="auditRemark"></textarea>
    </td>
</tr>
    <tr>
        <td class="name" >
            反馈说明：
        </td>
        <td colspan="7">
            <textarea class="form-control form-data" name="replyRemark" rows="3" placeholder=""></textarea>
        </td>
    </tr>
<tr>
    <td class="name" colspan="3">
        运输车辆图片
    </td>
    <td class="name" colspan="3">
        驾驶员图片
    </td>
    <td class="name" colspan="3">
        押运员图片
    </td>
</tr>
<tr>

    <td colspan="3" style="text-align: center">
        <div  id="car_div" style="margin-top: 20px;" >
        </div>
    </td>
    <td colspan="3" style="text-align: center">
        <div  id="driverImages_div" style="margin-top: 20px;" >
        </div>
    </td>
    <td colspan="3" style="text-align: center">
        <div id="supercargoImages_div" style="margin-top: 20px;">
        </div>
    </td>
</tr>
<tr>
    <td colspan="9">
        <button onclick="save()" class="btn btn-success">提交</button>
        <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
    </td>


</tr>

</table>
</div>


</body>
<script type="text/javascript">
    $(function () {

        var data = getData();
        buildSelect("/admin/device/listAll.do","#deviceId","id","name",{});
        buildSelect("/admin/buyCompany/listAll.do","#buyCompanyId","id","name",{"saleOrderId":data.id});
        buildSelect("/admin/transportCompany/listAll.do","#transportCompanyId","id","name",{"saleOrderId":data.id});
        var device =   $("#deviceId").children('option:selected').attr("b-data");
        $("input[name='unit']").val(JSON.parse(device).product.unit);
        $("#deviceId").change(function () {
            var device = $(this).children('option:selected').attr("b-data");
            $("input[name='unit']").val(JSON.parse(device).product.unit);
        });
        initData();
    });

    function initData(){
        var data = getData();
        if(null2empty(data["id"]) !==""){
            var id = data.id;
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/saleOrder/find.do",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                        if(!isNullOrUndefined(data.data.monitorValueLora)) {
                            $("[name='monitorValueLora']").val(data.data.monitorValueLora.calcValue);
                        } else {
                            $("[name='monitorValueLora']").val(0);
                        }
                        var  driver = data.data.driver;
                        if(!isNullOrUndefined(driver)){
                            initPageDate(driver, '.driver');
                        }
                        var  supercargo = data.data.supercargo;
                        if(!isNullOrUndefined(supercargo)){
                            initPageDate(supercargo, '.supercargo');
                        }
//                        $("#imgDiv img").attr("src",data.data.image);
                        addFileInfoToTable(data.data.carImageList,'car');
                        addFileInfoToTable(data.data.driverImagesList,'driverImages');
                        addFileInfoToTable(data.data.supercargoImagesList,'supercargoImages');
//                        addFileInfoToTable(data.data.peopleImageList,'people');
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }

    }

    function save() {
        var params = getPageDataByClass("form-data");
        if (strIsNull(params['auditRemark'])) {
            alert("请输入审核说明");
            return;
        }
        $.ajax({
            url: "/admin/saleOrder/remark.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    back();
                } else {
                    alert(data.msg);
                }
            }
        });
    }

    function uploadFile(fileType) {
        $.ajaxFileUpload({
            url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: fileType+'_input',                        //文件选择框的id属性
            dataType: 'text',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {//服务器成功响应处理函数
                var rpeObj = $.parseJSON(data);
                var fileInfoList = rpeObj.data;
                addFileInfoToTable(fileInfoList,fileType);

            }
        });
    }
    function addFileInfoToTable(fileInfoList,fileType){
        $(fileInfoList).each(function(index,file){
            var fileHtml = "<div  style='border-radius: 2px; width:48%;height:auto;float: left; border: 2px #ffffff solid;'>"+
                "<div style='height:auto;overflow:hidden;'><img class='image'style='height:auto;width:200px;height: 200px' src='"+getFileShowUrl(file.path)+"'></div>"+
                "<div align='center' style='word-wrap:break-word;display: none'><input type='hidden' name='"+fileType+"_id' value='"+file.id+"'>"+file.name+"</div>"+
                "<div align='center' style='height:80px;margin-bottom: 0px;'>"+
            "</div>";
            $(fileHtml).appendTo($("#"+fileType+"_div"));

        });
        $('.image').viewer();
        $("button[name='delete']").click(function(){
            var id = $(this).attr("extendData");
            $.ajax({
                type: "POST",
                url: "/file/delete.do?_t=" + new Date().getTime(),
                data: "fileId=" + id,

                success: function (result) {
                    alert("删除成功");
                },

                error: function (XMLHttpRequest, textStatus, thrownError) {
                    /* alert("系统异常");*/
                }
            });
            $(this).parent().parent().remove();
        });
    }
    //获取要展示的图片
    function getFileShowUrl(url){
        var extStart=url.lastIndexOf(".");
        var ext=url.substring(extStart,url.length).toUpperCase();
        if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
            return "/resources/images/timg.jpg";
        }else{
            return url;
        }
    }
    function back() {
        var data = getData();
        if(!isNullOrUndefined(data.back_url)){
            if(!isNullOrUndefined(data.back_id)){
                data["id"] = data.back_id;
                goto(data.back_url,data);
            }else {
                data["id"] = "";
                goto(data.back_url,data);
            }
        }else {
            goto("sale_order_list.html",{"process":data.process,"refuseFlag":data.refuseFlag});
        }

    }
    function showBuyCompany() {
        var localData = getData();
        var companyId = $("[name='buyCompanyId']").val();
        goto("buyCompany_show.html",
            {"id":companyId,back_url:'sale_order_remark.html','saleOrderId':localData.id,"process":localData.process,
                "refuseFlag":localData.refuseFlag});
    }
    function showTransCompany() {
        var localData = getData();
        var companyId = $("[name='transportCompanyId']").val();
        goto("transportCompany_show.html",
            {"id":companyId,back_url:'sale_order_remark.html','saleOrderId':localData.id,"process":localData.process,
                "refuseFlag":localData.refuseFlag});
    }
</script>
</html>